package vip.specimen.system.datasource.validation.question;

import vip.specimen.system.datasource.entity.question.QuestionProblemEntity;
import vip.specimen.system.service.question.ProblemService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * *@Author: 余浪人
 * *@Date：2021/4/28 10:56
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
public class QuestionUniqueImp implements ConstraintValidator<QuestionUnique, String> {
    @Resource
    private ProblemService problemService;
    @Resource
    private HttpServletRequest request;

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        if (null == s) return true;
        QuestionProblemEntity articleEntity = this.problemService.findByProblem(s);
        return null == articleEntity || articleEntity.getUuid().toString().equals(request.getParameter("uuid"));
    }
}
